<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header" v-if="!sidebarFold">
      <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="site-navbar__brand-lg" href="javascript:;">{{
          full_title
        }}</a>
        <!-- <a class="site-navbar__brand-mini" href="javascript:;">{{little_title}}</a> -->
      </h1>
    </div>
    <div class="site-navbar__body clearfix site-navbar-sidebar">
      <el-menu
        v-if="menuLayout != 'navbar'"
        class="site-navbar__menu"
        mode="horizontal"
      >
        <el-menu-item
          class="site-navbar__switch "
          index="0"
          @click="sidebarFold = !sidebarFold"
        >
          <icon-svg name="zhedie" class="zhedie_transform"></icon-svg>
        </el-menu-item>
      </el-menu>
      <!--  <el-menu class="site-navbar__menu "
        mode="horizontal"> -->
      <!--    {{breOpen}} - {{breLayout}} -->
      <breadcrumb v-if="breOpen && breLayout == 'header'"></breadcrumb>

      <MenuTree v-if="menuLayout == 'navbar'" modType="horizontal" />

      <!--   </el-menu> -->
      <!--  <el-tooltip
                  effect="dark"
                  content="主题色"
                  placement="bottom">
        <div class="top-bar__item">
          <top-color></top-color>
        </div>
      </el-tooltip> -->
      <div class="logout">
        <span title="退出" @click="logoutHandle()"></span>
      </div>
      <!-- <theme class="top-theme"></theme> -->
      <el-menu
        class="site-navbar__menu site-navbar__menu--right"
        mode="horizontal"
      >
        <el-menu-item class="site-navbar__avatar" index="3">
          <el-dropdown :show-timeout="0" placement="bottom" size="small">
            <span class="el-dropdown-link username"  @click="userHandle()">
              <!-- <img src="~@/assets/img/avatar.png" :alt="userName"> -->
              当前用户:{{ userName }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>

            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item divided icon="el-icon-user" @click.native="userHandle()">个人信息</el-dropdown-item>
              <el-dropdown-item
                divided
                icon="el-icon-key"
                @click.native="updatePasswordHandle()"
                >修改密码</el-dropdown-item
              >
              <el-dropdown-item
                divided
                icon="el-icon-remove-outline"
                @click.native="logoutHandle()"
                >退出</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password
      v-if="updatePassowrdVisible"
      ref="updatePassowrd"
    ></update-password>
  </nav>
</template>

<script>
import UpdatePassword from "./main-navbar-update-password";
import { clearLoginInfo } from "@/utils";
//import theme from "@/components/top/theme";
import breadcrumb from "@/components/breadcrumb";
import MenuTree from "@/components/menu-tree";

export default {
  data() {
    return {
      showColor: false,
      updatePassowrdVisible: false,
      full_title: "NG-UI",
      little_title: "NG"
    };
  },
  components: {
    UpdatePassword,
    breadcrumb,
   // theme,
    MenuTree
  },
  computed: {
    navbarLayoutType: {
      get() {
        return this.$store.state.common.navbarLayoutType;
      }
    },
    sidebarFold: {
      get() {
        return this.$store.state.common.sidebarFold;
      },
      set(val) {
        this.$store.commit("common/updateSidebarFold", val);
      }
    },
    mainTabs: {
      get() {
        return this.$store.state.common.mainTabs;
      },
      set(val) {
        this.$store.commit("common/updateMainTabs", val);
      }
    },
    userName: {
      get() {
        return this.$store.state.user.name;
      }
    },
    sidebarLayoutSkin: {
      get() {
        return this.$store.state.common.sidebarLayoutSkin;
      }
    },
    menuLayout: {
      get() {
        return this.$store.state.common.menuLayout;
      }
    },
    breLayout: {
      get() {
        return this.$store.state.common.breadcrumbLayout;
      }
    },
    breOpen: {
      get() {
        return this.$store.state.common.breadcrumbOpen;
      }
    }
  },
  methods: {
    // 修改密码
    updatePasswordHandle() {
      this.updatePassowrdVisible = true;
      this.$nextTick(() => {
        this.$refs.updatePassowrd.init();
      });
    },
    userHandle() {
        this.$router.push({name: 'userinfo'})
    },
    // 退出
    logoutHandle() {
      this.$confirm(`您确定要退出此系统?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          clearLoginInfo()
          this.$router.push({ name: 'login' })
        }).catch(() => {})
      
    }
  }
};
</script>
<style lang="scss">
.top-theme{
    line-height: 50px;
    height: 50px;
    float: right;
  }
  .site-navbar-sidebar {
    margin-left: 1px !important;
  }


  .site-navbar {
    .el-menu-item {
      padding: 0 10px;
    }
  }

  .site-navbar__avatar  {

    .username {
      font-size: 13px;
    }

    .el-dropdown-link {
      cursor: pointer; 
    }
    .el-icon-arrow-down {
      font-size: 12px;
    }

   
  }
 .logout {
    line-height: 50px;
    height: 50px;
    float: right;
    /* width: 50px; */
    /* vertical-align: middle; */
    /* margin: auto; */
    display: inline-flex;

    span {
      background:  url(~@/assets/img/logout.svg) no-repeat 0;
      height: 32px;
      float: right;
      width: 32px;
      vertical-align: middle;
      margin: auto;
      line-height: 50px;
      cursor: pointer;
    }

  }
  .down-url {
    float: right;
    padding-right: 20px;
    line-height: 50px;
  }
</style>
